package com.suanfa.collect;

import com.suanfa.util.ArrayUtils;

public class RotateArrayOnce {

    public static void main(String[] args) {
        RotateArrayOnce once = new RotateArrayOnce();
        int[] nums = {1,2,3,4,5,6,7,8,9,10};
        int k = 3;

        ArrayUtils.printArray(once.rotate(nums, k));
    }



    public int[] rotate(int[] nums, int k) {
        int cnt = nums.length;
        int[] arr = new int[ nums.length];
        int s1 = cnt-k;
        //填充前几位
        for(int i = s1, j=0; i< nums.length; i++, j++){
            arr[j] = nums[i];
        }
        //填充后几位
        for(int i = k, j=0; i< nums.length; i++, j++){
            arr[i] = nums[j];
        }
        return arr;
    }
}
